
<template>
  <div class="accountList">
    <div class="searchBox">
      <el-form :model="searchForm" ref="searchFormRef">
        <el-row>
          <el-form-item prop="phone">
            <div class="item">
              <span v-html="'账号'" class="nameSpan"></span>
              <el-input
                size="mini"
                v-model="searchForm.phone"
                placeholder="请输入账号"
              ></el-input>
            </div>
          </el-form-item>
          <el-form-item prop="name">
            <div class="item">
              <span v-html="'昵称'" class="nameSpan"></span>
              <el-input
                size="mini"
                v-model="searchForm.name"
                placeholder="请输入昵称"
              ></el-input>
            </div>
          </el-form-item>

          <el-form-item>
            <el-button
              @click="searchClick"
              icon="el-icon-search"
              type="primary"
              size="mini"
              >查询</el-button
            >
            <el-button icon="el-icon-refresh" size="mini" @click="resetClick"
              >重置</el-button
            >
          </el-form-item>
        </el-row>
      </el-form>
    </div>
    <div class="tableBox" ref="tableBoxRef">
      <el-table
        :height="655"
        v-loading="tableLoading"
        :header-cell-style="{
          background: '#F8F8F8',
          color: '#333',
          fontSize: '16px',
          fontWeight: '700',
        }"
        border
        :data="tableData"
        style="width: 100%"
      >
        <el-table-column width="100px" prop="photoImg" align="center" label="头像">
          <template slot-scope="scope">
            <div>
              <div v-if="scope.row.photoImg!=''">
                <el-image
                  class="imgSize"
                  :src="scope.row.photoImg"
                  fit="contain"
                  :preview-src-list="[scope.row.photoImg]"
                ></el-image>
              </div>
              <div v-else>
                <img
                  style="height: 80px; width: 80px"
                  src="../../assets/images/tx.png"
                >
              </div>
            </div>
          </template>
        </el-table-column>
        <el-table-column sortable prop="phone" align="center" label="用户账号">
        </el-table-column>
        <el-table-column prop="pageSource" align="center" label="注册时间">
          <template slot-scope="scope">{{
            scope.row.createTime | formatDate
          }}</template>
        </el-table-column>
        <el-table-column prop="name" align="center" label="用户昵称">
        </el-table-column>
        <el-table-column prop="occupation" align="center" label="职业">
        </el-table-column>
        <el-table-column width="300px" prop="intro" align="center" label="个人简介">
        </el-table-column>
        <el-table-column
          prop="posterNum"
          align="center"
          sortable
          label="发布动态数"
        >
        </el-table-column>
        <el-table-column
          sortable
          prop="commentNum"
          align="center"
          label="评论数"
        >
        </el-table-column>
        <el-table-column
          sortable
          prop="beGoodNum"
          align="center"
          label="被赞次数"
        >
        </el-table-column>
        <el-table-column
          sortable
          prop="likeUpNum"
          align="center"
          label="关注作者数"
        >
        </el-table-column>
        <el-table-column
          sortable
          prop="likePosterNum"
          align="center"
          label="关注动态数"
        >
        </el-table-column>
        <el-table-column sortable prop="fansNum" align="center" label="粉丝数">
        </el-table-column>
      </el-table>

       <el-card class="footer" v-if="total > 0">
         <div>
        <el-pagination
          background
          @size-change="handleSizeChange"
          @current-change="handleCurrentChange"
          :current-page="pageNum"
          :page-sizes="[15, 30, 50, 100]"
          :page-size="pageSize"
          layout="total, sizes, prev, pager, next, jumper"
          :total="total"
        >
        </el-pagination>
      </div>
       </el-card>
    </div>
  </div>
</template>

<script>
export default {
  data() {
    return {
      searchForm: {
        phone: "",
        name: "",
      },
      tableLoading: false,
      tableHeight: 50,
      tableData: [],
      pageNum: 1,
      pageSize: 15,
      total: 0,
    };
  },

  created() {
    this.getUserList();
  },
  methods: {
    searchClick() {
      this.pageNum = 1;
      this.getUserList();
    },
    resetClick() {
      this.$refs.searchFormRef.resetFields();
      this.pageNum = 1;
      this.getUserList();
    },

    /**
     * 获取用户列表
     * @param {*}
     */
    async getUserList() {
      this.tableLoading = true;
      const res = await this.$api.userList({
        pageSize: this.pageSize,
        pageNum: this.pageNum,
        ...this.searchForm,
      });
      this.total = res.data.result.total;
      this.tableData = res.data.result.list;
      this.tableLoading = false;
    },

    /**
     * 切换页面大小
     * @param {*} val
     */
    handleSizeChange(val) {
      console.log(`每页 ${val} 条`);
      this.pageSize = val;
      this.getUserList();
    },

    /**
     * 页码切换
     * @param {*} val
     */
    handleCurrentChange(val) {
      console.log(`当前页: ${val}`);
      this.pageNum = val;
      this.getUserList();
    },
  },
};
</script>

<style lang="less" scoped>
.accountList {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 20px;
  .searchBox {
    .el-row {
      display: flex;
      flex-wrap: wrap;
      .el-form-item {
        margin-bottom: 0;
      }
      .item {
        display: flex;
        align-items: center;
        margin-right: 20px;
        .nameSpan {
          padding-right: 10px;
          box-sizing: border-box;
          white-space: nowrap;
        }
        .el-input {
          width: 162px;
        }
      }
    }
  }


}
/deep/.el-button--success.is-plain {
  color: #fff;
  border-color: #409eff;
  background-color: #409eff;
}
/deep/.el-form-item {
  margin-bottom: 12px;
}
.content {
  height: 35vh;
  overflow-x: hidden;
}
/deep/.el-upload--picture-card {
  width: 400px;
  height: 270px;
}
/deep/.el-upload--picture-card i {
  margin-top: 128px;
}
.imgSize {
  height: 80px;
}
</style>